@file:Suppress("IMPLICIT_CAST_TO_ANY")

package com.example.androidkt.first

import kotlin.math.max


/**
 * 定义一个函数的语法规则
 * */

fun funName() {
    /**
     *  var 可以重新赋值 val不可以
     * */
    val a = 10
    var b: Int = 5

    b += 3   // b = b + 3
}

fun largerNumber1(a: Int, b: Int): Int {
    return max(a, b)
}

fun largerNumber2(a: Int, b: Int) = max(a, b)

fun largerNumber3(a: Int, b: Int): Int {
    var value = 0
    if (a > b) {
        value = a
    } else {
        value = b
    }
    return value
}

fun largerNumber4(a: Int, b: Int): Int {
    return if (a > b) {
        a
    } else {
        b
    }
}

fun largerNumber5(a: Int, b: Int) = if (a > b) {
    a
} else {
    b
}

fun largerNumber6(a: Int, b: Int) = if (a > b) a else b


fun getScore(name: String) = if (name == "Tom") {
    1
} else if (name == "Jack") {
    11
} else {
    22
}

fun getScore1(name: String) =
    when (name) {
        "Tom" -> 1
        "Jack" -> 1
        else -> 0
    }

fun getScore2(name: Number) =
    when (name) {
        is Int -> println("${name}是Int类型")
        is Double -> println("${name}是Double类型")
        else -> println("${name}不是数字")
    }

fun getScore3(name: String) = when {
    name.startsWith("zzz") -> println("$name 开头是 zzz")
    name == "wawa" -> println("$name 是 wawa")
    else -> {
        println("$name 啥也不是")
    }
}

fun getScore4(name: String, sex: String) = when {
    name.startsWith("zzz") -> println("$name 开头是 zzz")
    name == "wawa" || name == "hehe" -> println("$name 是 wawa 或者 hehe")
    sex == "女" -> println("$name 是女人")
    else -> {
        println("$name 啥也不是")
    }
}

fun for1() {
    for (i in 1..10) {
        println(i)
    }
}

fun for2() {
    for (i in 0 until 10) {
        println(i)
    }
}

fun for3() {
    for (i in 1..10 step 3) {
        println(i)
    }
}

fun for4() {
    for (i in 11 downTo 1) {
        println(i)
    }
}

fun for5() {
    for (i in 11 downTo 1 step 2) {
        println(i)
    }
}

fun for6() {
    out@ for (i in 1..5) {
        println("$i    外层")
        for (j in 1..3) {
            if (j == i) {
                break@out
            }
            println("$j    内层")

        }
    }
}

fun for7() {
    out@ for (i in 1..5) {
        println("$i    外层")
        for (j in 1..3) {
            if (j == i) {
                continue@out
            }
            println("$j    内层")
        }
    }
}

/**
 *
 * */

fun doS(person: Person?) {
    person?.let {
        person.name
    }
}

fun test1() {
    var a = null
    var b = 3

    if (a != null) {
        a
    } else {
        b
    }

    val c = a ?: b

    println(c)
}


fun main() {
    test1()

    println("--------------------------------------------")

    for7()

    println("--------------------------------------------")

    parm1(str = "")
    parm2(1)
}

fun parm1(age : Int = 10,str : String){
    println("age $age , str $str")
}
fun parm2(age : Int ,str : String = "xx"){
    println("age $age , str $str")
}
fun parm3(age : Int =10 ,str : String ="xx"){
    println("age $age , str $str")
}
























